﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NimbleTextKeygen
{
    public class AssemblyVersion : IComparable<AssemblyVersion>
    {
        private string rawVersion;

        public int[] parts
        {
            get;
            private set;
        }

        public AssemblyVersion(string version)
        {
            int num;
            this.rawVersion = version;
            List<int> nums = new List<int>();
            string[] strArrays = version.Split(new char[] { '.' });
            if ((int)strArrays.Length != 4)
            {
                throw new ArgumentException(string.Format("A version number must have four parts, a.b.c.d that are each numeric. This one only has {0} parts", (int)strArrays.Length));
            }
            string[] strArrays1 = strArrays;
            for (int i = 0; i < (int)strArrays1.Length; i++)
            {
                string str = strArrays1[i];
                if (!int.TryParse(str, out num))
                {
                    throw new ArgumentException(string.Format("A version number must have four parts, a.b.c.d that are each numeric. This part is not numeric: '{0}'", str));
                }
                nums.Add(num);
            }
            this.parts = nums.ToArray();
        }

        public int CompareTo(AssemblyVersion other)
        {
            for (int i = 0; i < (int)this.parts.Length; i++)
            {
                if (this.parts[i] != other.parts[i])
                {
                    return this.parts[i].CompareTo(other.parts[i]);
                }
            }
            return 0;
        }

        public override string ToString()
        {
            return this.rawVersion;
        }
    }
}
